// Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;

namespace Microsoft.WindowsAPICodePack.DirectX.DirectXUtilities
{
    public static class Camera
    {
        public static Matrix4F MatrixLookAtLH(Vector3F eye, Vector3F at, Vector3F up)
        {
            Vector3F right, vec;
            
            vec = at - eye;
            vec.NormalizeInPlace();
            right = Vector3F.Cross(up, vec);
            up = Vector3F.Cross(vec, right);
            right.NormalizeInPlace();
            up.NormalizeInPlace();
            return new Matrix4F(
                right.x,
                up.x,
                vec.x,
                0.0f,

                right.y,
                up.y,
                vec.y,
                0.0f,

                right.z,
                up.z,
                vec.z,
                0.0f,

                -Vector3F.Dot(right, eye),
                -Vector3F.Dot(up, eye),
                -Vector3F.Dot(vec, eye),
                1.0f
            );
        }

        public static Matrix4F MatrixPerspectiveFovLH(float fovy, float aspect, float zn, float zf)
        {
            Matrix4F ret = new Matrix4F();
            ret._11 = 1.0f / (aspect * (float)Math.Tan(fovy / 2));
            ret._22 = 1.0f / (float)Math.Tan(fovy / 2);
            ret._33 = zf / (zf - zn);
            ret._34 = 1;
            ret._43 = (zf * zn) / (zn - zf);
            ret._44 = 0;
            return ret;
        }
    }
}
